package cn.source.web.controller.db;

import cn.source.common.core.controller.BaseController;
import cn.source.common.core.domain.AjaxResult;
import cn.source.common.core.page.TableDataInfo;
import cn.source.common.utils.DateUtils;
import cn.source.zk.domain.dto.BaseData2TableDTO;
import cn.source.zk.domain.entity.DbWave;
import cn.source.zk.domain.vo.Wave2PageVO;
import cn.source.zk.service.DbWaveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * @author shiqi
 * @create 2025-05-22 15:00
 */
@RestController
@RequestMapping("/db/dbWave")
@Slf4j
public class DbWaveController extends BaseController {

    @Autowired
    private DbWaveService dbWaveService;

    @GetMapping("/list")
    public TableDataInfo getWaveByPage(BaseData2TableDTO baseData2TableDTO) {
        startPage();

        List<Wave2PageVO> list =  dbWaveService.getWaveByPage(baseData2TableDTO);

        return getDataTable(list);
    }

    @GetMapping("/getWaveByTdGuid")
    public AjaxResult getWaveByTdGuid(@RequestParam("tdGuid")String tdGuid, @RequestParam("timedate")String timedate) {

        log.info("tdGuid:{},timedate:{}",tdGuid,timedate);
        // 格式化为目标格式
        String formattedDateTime = DateUtils.dateFormat(timedate, "yyyy-MM-dd HH:mm:ss");

        DbWave dbWave = dbWaveService.getWaveByTdGuid(tdGuid,formattedDateTime);

        return AjaxResult.success(dbWave);
    }

}
